import { observable, action } from 'mobx';
import Api from '../apis/attachment';
import ListBaseStore from './ListBaseStore';

const initState = {
  loading: false,
};

/**
 * 邮件 - 附件中心
 */
export default class EmailAttachmentStore extends ListBaseStore {
  @observable loading = initState.loading;

  @action setState = (params = {}) => {
    Object.keys(params).forEach((key) => {
      this[key] = params[key];
    });
    return this;
  };

  clearSort = () => {
    this.comsWeaTableStore.getDatas(this.sessionkey, 1, '', {
      orderkey: '',
      sortOrder: '',
    });
  };

  // 加载列表数据
  @action doTableLoading = (params) => {
    this.showLoading(true);
    let resultParams = this.getFormParams();
    let commonParams = {};
    resultParams = { ...resultParams, ...commonParams, ...params };

    Api.list(resultParams).then((result) => {
      const sessionkey = result.sessionkey;
      this.sessionkey = sessionkey;
      this.comsWeaTableStore.getDatas(sessionkey, 1);

      this.showLoading(false);
    });
  };

  // 初始化收藏的帖子页面查询条件
  @action initConditionDatas = (params) => {
    Api.condition(params).then((result) => {
      this.conditioninfo = result.conditioninfo;

      this.initFormFields(this.conditioninfo); // 一定要先初始化initFormFields表单对象
    });
  };
}
